package uy.com.nfc.localassigner.adapters;

import java.util.List;

import uy.com.nfc.localassigner.R;
import android.app.Activity;
import android.content.Context;
import android.graphics.Color;
import android.graphics.Typeface;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.example.nfctagcommons.classes.PointCheck;
import com.example.nfctagcommons.utils.TimeUtils;

public class RecordsListAdapter extends ArrayAdapter<String> { 
	private static final int GRAY = Color.argb(238, 230, 230, 230);
	private List<PointCheck> localCheckList;
	private Activity activity;
	private Typeface customTypeface;
	public RecordsListAdapter(Activity activity, String[] items, List<PointCheck> localCheckList) {
		super(activity.getApplicationContext(), R.layout.activity_main, items);
		this.activity = activity;
		this.localCheckList = localCheckList;
		customTypeface = Typeface.createFromAsset(activity.getAssets(), "fonts/AliquamREG.ttf");
	}
	
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder viewHolder = null;
		if (convertView == null) {
			LayoutInflater inflater = (LayoutInflater) activity.getApplicationContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			convertView = inflater.inflate(R.layout.view_record, parent, false);
			viewHolder = new ViewHolder();
			viewHolder.mainContainer = (LinearLayout) convertView.findViewById(R.id.record_view_main_container);
		    viewHolder.localName = (TextView) convertView.findViewById(R.id.record_view_local_name);
		    viewHolder.localCheckHour = (TextView) convertView.findViewById(R.id.record_view_hour);
		    viewHolder.localCheckDate = (TextView) convertView.findViewById(R.id.record_view_date);
//		    viewHolder.localCheckComment = (TextView) convertView.findViewById(R.id.record_view_comment);
//		    viewHolder.localImage = (ImageView) convertView.findViewById(R.id.record_view_local_image);
		    convertView.setTag(viewHolder);
		}else{
			viewHolder = (ViewHolder) convertView.getTag();
		}
		viewHolder.mainContainer.setBackgroundColor(GRAY);
		PointCheck localCheck = localCheckList.get(position);
		viewHolder.localName.setText(localCheck.getLocalName());
		viewHolder.localCheckHour.setText(TimeUtils.formatTimeHHMM(localCheck.getTimestamp()));
		viewHolder.localCheckDate.setText(TimeUtils.formatTimeDDMMAAAA(localCheck.getTimestamp()));
		
		viewHolder.localName.setTypeface(customTypeface);
		viewHolder.localCheckHour.setTypeface(customTypeface);
		viewHolder.localCheckDate.setTypeface(customTypeface);
		
//	    viewHolder.localCheckComment.setText(localCheck.getComment());
	    //viewHolder.localImage
		return convertView; 
	}
	static class ViewHolder {
		protected LinearLayout mainContainer;
		protected TextView localName;
		protected TextView localCheckHour;
		protected TextView localCheckDate;
//		protected TextView localCheckComment;
//		protected ImageView localImage;
	}
}
